package com.vito.dcs.sys.constructionVehicle.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.authoriza.cache.SessionMap;
import com.vito.base.authoriza.model.UserModel;
import com.vito.base.exception.ParamErrorException;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.base.util.Validata;
import com.vito.dcs.sys.constructionVehicle.model.SysConstructionVehicleModel;
import com.vito.dcs.sys.constructionVehicle.service.SysConstructionVehicleService;

/**
 * 工程车辆表请求控制器
 * @author  Feng J. E-mail: 
 * @version 0.1.1
 * @date    2019-3-28 14:15:43
 */
@Controller
@RequestMapping("/dcs/sys/constructionVehicle")
public final class SysConstructionVehicleAction extends BaseAction {
	
	private static final Logger log = LoggerFactory.getLogger(SysConstructionVehicleAction.class);
	
	@Reference
	private SysConstructionVehicleService sysconstructionvehicleServiceImpl;
	
	/**
	 * 保存工程车辆表
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 14:15:43
	 * @return  code:状态码 ,msg:提示信息
	 * @param   sysconstructionvehicle 需要保存的工程车辆表对象
	*			3434
	 *		 	<li>SectionId:标段ID 不能为null 或空字符串</li>
	 *		 	<li>DeviceVid:设备VID，对应的内置GPS 不能为null 或空字符串</li>
	 *		 	<li>VehicleName:设备名称，工程车辆的名称 不能为null 或空字符串</li>
	 *		 	<li>VehicleType:设备型号，01 摊铺机  02 胶轮压路机  03 钢轮压路机 不能为null 或空字符串</li>
	 */
	@RequestMapping("saveSysConstructionVehicle")
	@ResponseBody
	public Result saveSysConstructionVehicle(@RequestBody SysConstructionVehicleModel sysconstructionvehicle){
		Result res = new Result();
        UserModel user = SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			Validata.isNullOrEmpty(sysconstructionvehicle, "工程车辆表不能为空");
			Validata.isNullOrEmpty(sysconstructionvehicle.getSectionId(), "标段ID不能为空");
			Validata.isNullOrEmpty(sysconstructionvehicle.getDeviceVid(), "设备MAC不能为空");
			Validata.isNullOrEmpty(sysconstructionvehicle.getVehicleName(), "设备名称不能为空");
			Validata.isNullOrEmpty(sysconstructionvehicle.getVehicleType(), "设备型号不能为空");
			sysconstructionvehicleServiceImpl.saveSysConstructionVehicle(sysconstructionvehicle);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("保存失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 分页查询工程车辆表
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 14:15:43
	 * @return  {code:0,data:{total:20,rows:[{}...]}}
	 * @param   sysconstructionvehicle 依靠工程车辆表对象分页查询
	 *          <li>pageNo default 1</li>
	 *          <li>pageSize default 15</li>
	 */
	@RequestMapping("querySysConstructionVehicleByPage")
	@ResponseBody
	public Result querySysConstructionVehicleByPage(SysConstructionVehicleModel sysconstructionvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			Validata.isNullOrEmpty(sysconstructionvehicle, "工程车辆表不能为空");
			if(sysconstructionvehicle.getStartTime()!=null&&!"".equals(sysconstructionvehicle.getStartTime())){
				try{
					Validata.is(sysconstructionvehicle.getStartTime().toString(),"开始施工时间格式不合法","DATE");
					sysconstructionvehicle.setStartTime(sysconstructionvehicle.getStartTime());
				}catch(ParamErrorException e){
				}
				Validata.is(sysconstructionvehicle.getStartTime().toString(),"开始施工时间格式不合法","DATE_TIME");
			}
			if(sysconstructionvehicle.getUpdateTime()!=null&&!"".equals(sysconstructionvehicle.getUpdateTime())){
				try{
					Validata.is(sysconstructionvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE");
					sysconstructionvehicle.setUpdateTime(sysconstructionvehicle.getUpdateTime());
				}catch(ParamErrorException e){
				}
				Validata.is(sysconstructionvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE_TIME");
			}
			res.setData(sysconstructionvehicleServiceImpl.querySysConstructionVehicleByPage(sysconstructionvehicle));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 查询一条工程车辆表
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 14:15:43
	 * @return  {code:0,data:{...}}
	 * @param   sysconstructionvehicle 依靠工程车辆表对象查询
	 */
	@RequestMapping("querySysConstructionVehicle")
	@ResponseBody
	public Result querySysConstructionVehicle(SysConstructionVehicleModel sysconstructionvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			if(sysconstructionvehicle.getStartTime()!=null&&!"".equals(sysconstructionvehicle.getStartTime())){
				try{
					Validata.is(sysconstructionvehicle.getStartTime().toString(),"开始施工时间格式不合法","DATE");
					sysconstructionvehicle.setStartTime(sysconstructionvehicle.getStartTime());
				}catch(ParamErrorException e){
				}
				Validata.is(sysconstructionvehicle.getStartTime().toString(),"开始施工时间格式不合法","DATE_TIME");
			}
			if(sysconstructionvehicle.getUpdateTime()!=null&&!"".equals(sysconstructionvehicle.getUpdateTime())){
				try{
					Validata.is(sysconstructionvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE");
					sysconstructionvehicle.setUpdateTime(sysconstructionvehicle.getUpdateTime());
				}catch(ParamErrorException e){
				}
				Validata.is(sysconstructionvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE_TIME");
			}
			res.setData(sysconstructionvehicleServiceImpl.querySysConstructionVehicle(sysconstructionvehicle));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	@RequestMapping("/queryIsValidateMac")
	@ResponseBody
	public Result queryIsValidateMac(SysConstructionVehicleModel sysconstructionvehicle){
		Result res = new Result();
		try {
			Integer queryIsValidateMac = sysconstructionvehicleServiceImpl.queryIsValidateMac(sysconstructionvehicle);
			res.setCode(Result.CODE_OK);
			res.setData(queryIsValidateMac);
		} catch (Exception e) {
			log.error("校验mac出错", e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg("校验mac出错");
		}
		return res;
	}
		
	/**
	 * 更新工程车辆表对象
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 14:15:43
	 * @return  {code:0,data:10}
	 * @param   sysconstructionvehicle 依靠工程车辆表对象的id变更传入的其他属性值
	 *		 	<li>Id:主键ID 不能为null 或空字符串</li>
	 *		 	<li>SectionId:标段ID 不能为null 或空字符串</li>
	 *		 	<li>DeviceVid:设备VID，对应的内置GPS 不能为null 或空字符串</li>
	 *		 	<li>VehicleName:设备名称，工程车辆的名称 不能为null 或空字符串</li>
	 *		 	<li>VehicleType:设备型号，01 摊铺机  02 胶轮压路机  03 钢轮压路机 不能为null 或空字符串</li>
	 */
	@RequestMapping("updateSysConstructionVehicle")
	@ResponseBody
	public Result updateSysConstructionVehicle(@RequestBody SysConstructionVehicleModel sysconstructionvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
		
		Validata.isNullOrEmpty(sysconstructionvehicle.getId(),"主键ID不能为空");
		Validata.isNullOrEmpty(sysconstructionvehicle.getSectionId(), "标段ID不能为空");
		Validata.isNullOrEmpty(sysconstructionvehicle.getDeviceVid(), "设备VID不能为空");
		Validata.isNullOrEmpty(sysconstructionvehicle.getVehicleName(), "设备名称不能为空");
		Validata.isNullOrEmpty(sysconstructionvehicle.getVehicleType(), "设备型号不能为空");
            sysconstructionvehicle.setUpdateUser(user.getUserId());
			res.setData(sysconstructionvehicleServiceImpl.updateSysConstructionVehicle(sysconstructionvehicle));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.UPDSUC);
			
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("更新失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 删除工程车辆表对象
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 14:15:43
	 * @return  {code:0,data:10}
	 * @param   sysconstructionvehicle 删除工程车辆表对象的 checkeds 标识的id对应的数据
	 */
	@RequestMapping("deleteSysConstructionVehicle")
	@ResponseBody
	public Result deleteSysConstructionVehicle(SysConstructionVehicleModel sysconstructionvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			Validata.isNullOrEmpty(sysconstructionvehicle.getCheckeds(), "所选项不能为空");
			
			res.setData(sysconstructionvehicleServiceImpl.deleteSysConstructionVehicle(sysconstructionvehicle));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELCOM);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("删除失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
}



